/*
{
"状态":1,
"名称":"获取-店铺属性值",
"作者":"马学兵",
"创建时间":"2018-12-30",
"功能":"获取-店铺属性值",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
--前端调用
DECLARE @dict_id VARCHAR(10)

--定义变量
DECLARE @sql NVARCHAR(max)
DECLARE @field NVARCHAR(100)

set @dict_id='{dict_id}'

if @dict_id='10801'
begin 
	SELECT 'all' as val
	return 
end 

SET @field=CASE  @dict_id 
WHEN '10802' THEN 'rtrim(entity_code) '
WHEN '10803' THEN 'entityName'
WHEN '10804' THEN 'short_name'
WHEN '10805' THEN 'entity_type'
WHEN '10806' THEN 'company'
WHEN '10807' THEN 'area' 
WHEN '10808' THEN '[group]'
WHEN '10809' THEN 'province'
WHEN '10810' THEN 'city'
WHEN '10811' THEN 'county'
WHEN '10812' THEN 'supervisor' else '' END 

if @field=''
begin 
	RAISERROR ('店铺不存在该属性', 16 ,1 ) ; 
	return
end 

SET @sql='SELECT distinct  {field} as val FROM dbo.b_entity where  {field}<>'''''
SET @sql=REPLACE(@sql,'{field}',@field)
EXEC (@sql)
 